package sanphone.com.runningschool.JuShou;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.util.List;
import sanphone.com.runningschool.R;
import sanphone.com.runningschool.entity.JuShouInfo;

public class Jushou_ListViewAdapter extends BaseAdapter {
    private Context mContext;
    List<JuShouInfo> juShou_infos;

    public Jushou_ListViewAdapter(Context context, List<JuShouInfo> infos) {
        mContext = context;
        juShou_infos = infos;
    }


    @Override
    public int getCount() {
        return juShou_infos.size();
    }

    @Override
    public Object getItem(int position) {
        return juShou_infos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder;
        final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (view == null) {
            holder = new ViewHolder();
            view = inflater.inflate(R.layout.jushou_listview_item, null);
            holder.iconImage = view.findViewById(R.id.paotui_publisher_icon);

            holder.detailText = view.findViewById(R.id.detail);
            holder.nameText = view.findViewById(R.id.paotui_publisher_name);
            holder.contentText = view.findViewById(R.id.paotui_publisher_content);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        //控件和数据之间进行绑定
        final JuShouInfo j= juShou_infos.get(position);
        Picasso.with(mContext).load(R.drawable.icon)
                .placeholder(R.mipmap.ic_launcher)
                .resize(60, 60)
                .onlyScaleDown()
                .into(holder.iconImage);

        holder.nameText.setText(j.getNickName());
        holder.contentText.setText("物品名称："+j.getThingName()+"\n"+"物品重量："+j.getThingWeight()
                +"\n起始时间："+j.getThingTime()
                +"\n送达时间："+j.getDeliverTime()+"\n起始地址："+j.getThingPlace()+
                "\n送达地址："+j.getDeliverPlace()+"\n酬劳："+j.getMoney());
        holder.contentText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               Intent intent =new Intent(mContext,JuShouDetailActivity.class);
               intent.putExtra("nickName",j.getNickName());
               intent.putExtra("thingName" ,j.getThingName());
               intent.putExtra("thingPlace",j.getThingPlace());
               intent.putExtra("deliverPlace",j.getDeliverPlace());
                intent.putExtra("thingTime",j.getThingTime());
               intent.putExtra("deliverTime",j.getDeliverTime());
               intent.putExtra("money",j.getMoney());
               intent.putExtra("detail",j.getOtherDeatil());
               intent.putExtra("thingWeight",j.getThingWeight());
               intent.putExtra("behaviorId",j.getBehaviorId());
               mContext.startActivity(intent);
            }
        });
        holder.detailText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(mContext,JuShouDetailActivity.class);
                intent.putExtra("nickName",j.getNickName());
                intent.putExtra("thingName" ,j.getThingName());
                intent.putExtra("thingPlace",j.getThingPlace());
                intent.putExtra("deliverPlace",j.getDeliverPlace());
                intent.putExtra("thingTime",j.getThingTime());
                intent.putExtra("deliverTime",j.getDeliverTime());
                intent.putExtra("money",j.getMoney());
                intent.putExtra("detail",j.getOtherDeatil());
                intent.putExtra("thingWeight",j.getThingWeight());
                intent.putExtra("behaviorId",j.getBehaviorId());

                mContext.startActivity(intent);
            }
        });
        return view;
    }

    class ViewHolder {
        ImageView iconImage;
        TextView nameText, contentText,detailText;

    }



}




